package com.example.login.Service;

import com.example.login.Mapper.GoodsMap;
import com.example.login.Pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;

@Service("SearchGoodsService")
public class SearchGoodsService {
    @Autowired
    GoodsMap goodsMap;
    public ArrayList<ArrayList<Goods>> allGoods(boolean sort){
        ArrayList<ArrayList<Goods>> lists=new ArrayList<>();
        ArrayList<Goods> goods=goodsMap.getGoods();
        if(sort)
        {
            Collections.sort(goods);
        }
        ArrayList<Goods> temp=new ArrayList<>(3);
        for(int i=0;i<goods.size();i++)
        {
            temp.add(goods.get(i));
            if(i%3==2||i==goods.size()-1)
            {
                lists.add(temp);
                 temp=new ArrayList<>(3);
            }
        }
        System.out.println(lists);
        return lists;
    }
    public ArrayList<ArrayList<Goods>> mobileGoods(boolean sort){
        ArrayList<ArrayList<Goods>> lists=new ArrayList<>();
        ArrayList<Goods> goods=goodsMap.getMobile();
        if(sort)
        {
            Collections.sort(goods);
        }
        ArrayList<Goods> temp=new ArrayList<>(3);
        for(int i=0;i<goods.size();i++)
        {
            temp.add(goods.get(i));
            if(i%3==2||i==goods.size()-1)
            {
                lists.add(temp);
                temp=new ArrayList<>(3);
            }
        }
        System.out.println(lists);
        return lists;
    }
    public ArrayList<ArrayList<Goods>> PCGoods(boolean sort){
        ArrayList<ArrayList<Goods>> lists=new ArrayList<>();
        ArrayList<Goods> goods=goodsMap.getPc();
        if(sort)
        {
            Collections.sort(goods);
        }
        ArrayList<Goods> temp=new ArrayList<>(3);
        for(int i=0;i<goods.size();i++)
        {
            temp.add(goods.get(i));
            if(i%3==2||i==goods.size()-1)
            {
                lists.add(temp);
                temp=new ArrayList<>(3);
            }
        }
        System.out.println(lists);
        return lists;
    }
    public ArrayList<ArrayList<Goods>> MP3Goods(boolean sort){
        ArrayList<ArrayList<Goods>> lists=new ArrayList<>();
        ArrayList<Goods> goods=goodsMap.getMp3();
        if(sort)
        {
            Collections.sort(goods);
        }
        ArrayList<Goods> temp=new ArrayList<>(3);
        for(int i=0;i<goods.size();i++)
        {
            temp.add(goods.get(i));
            if(i%3==2||i==goods.size()-1)
            {
                lists.add(temp);
                 temp=new ArrayList<>(3);
            }
        }
        System.out.println(lists);
        return lists;
    }
    public ArrayList<ArrayList<Goods>> allGoodsOrderBySale(){
        ArrayList<ArrayList<Goods>> lists=new ArrayList<>();
        ArrayList<Goods> goods=goodsMap.getGoodsOrderBySale();
        ArrayList<Goods> temp=new ArrayList<>(3);
        for(int i=0;i<goods.size();i++)
        {
            temp.add(goods.get(i));
            if(i%3==2||i==goods.size()-1)
            {
                lists.add(temp);
                temp=new ArrayList<>(3);
            }
        }
        System.out.println(lists);
        return lists;
    }
}
